/** Header file for planet destruction
*	Created 17.9.2009 by Raymond; common.h massacre
*	*/
#ifndef PHYSICS_H
#define PHYSICS_H

#include <list>
#include "common.h"
#include "databank.h"

class Shot;
class Particle;

class Gravitated {
public:
    double position[2];
    double velocity[2];
    double mass;
    
    GravitatedType type;	// Reference to either a particle or shot
    union {			// At sensible times, functions are called from
    	Particle *p;		// doPhysics
    	Shot *s;
    	void *ptr;
    }t;	// I really hope this union works like I think it will
    	
};

/** Handles all in-game physics */
class PhysicsModule {
	DataBank* data;
	
	std::list<Gravitated *> gob;
	
	Config *cfg;
public:
	PhysicsModule(DataBank* d) { data = d; cfg = data->getconfig();}
	
	std::list<Gravitated *> getGravitated() { return gob; } // Temporary function
	
	Gravitated *addGravitated(void)
		{	Gravitated *g = new Gravitated;
			gob.push_back(g);
			return g;
		}
	Gravitated *addGravitated(double position[2], double velocity[2], double mass, GravitatedType t,void *ptr)
		{	Gravitated *g = addGravitated();
			
			for(int i=0;i<2;i++) {
				g->position[i] = position[i];
				g->velocity[i] = velocity[i];
			}
			g->mass = mass;
			
			g->type = t;
			g->t.ptr = ptr;
			
			return g;
		}
	
	/// Processes physics. Returns when no more active shots
	bool doPhysics(double time);
	
	void clear();
};

#endif

